%% 读取数据
data_read_args.branch_file_path="yantian402/运行方式1-branch_reordered.xlsx";
data_read_args.source_file_path="yantian402/capacity.xlsx";
data_read_args.load_file_path="yantian402/all_load_node_mapped.xlsx";
[buses, branches, substations, init_sw] = yantian_vdata(data_read_args);
Nbr = height(branches);
Nbus = height(buses);

%% 建立图模型
Edgetable = branches(:, {'bus1id', 'bus2id', 'name', 'is_sw'});
Edgetable = mergevars(Edgetable, {'bus1id', 'bus2id'}, "NewVariableName", 'EndNodes');
Edgetable.fixed = ~Edgetable.is_sw;
Edgetable.is_sw = [];
G = graph(Edgetable);

%% 设置初始运行拓扑结构
brid = findedge(G, init_sw.bus1id(~init_sw.status), init_sw.bus2id(~init_sw.status));
initial_grid = true(Nbr, 1);
initial_grid(brid) = false;

%% 设置初始拓扑中所有在运支路故障，选择任意支路节点，上优化求解器
fault_br_name=G.Edges.name(initial_grid);
fault_br_eid=find(initial_grid);
sol = cell(length(fault_br_eid), 1);

for k = 1:length(fault_br_eid)
    sol{k} = reconstruct_branch_fault(G, fault_br_eid(k), initial_grid, buses, branches, substations);
end
%% 存储结果
save solution.mat sol initial_grid G fault_br_name;


